package layui.controller.product;

import com.google.gson.Gson;
import layui.controller.BaseServlet;
import layui.dao.ProductDao;
import layui.dao.impl.ProductDaoImpl;
import layui.vo.ResponseData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author lzp
 * @Date 2023-11-22
 */
@WebServlet("/admin/product/product_remove")
public class RemoveProductServlet extends BaseServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取删除的id
        String productId = req.getParameter("pid");

        // 第二：对数据进行合法性验证（略）

        // 第三：加工处理 - 业务逻辑 - 调用DAO
        ProductDao productDao = new ProductDaoImpl();
        int row = productDao.delete(productId);

        // 第四：响应
        if(row == 1) {
            print(resp,successJson(200,"删除成功",null));
            return ;
        }
        print(resp,errorJson(500,"删除失败",null)) ;

    }
}
